package api

import (
	"customer/api/handler"
	"customer/api/middleware"
	"customer/consts"
	"github.com/gin-gonic/gin"
	"github.com/share309/gojwt"
)

func LoadRouters(r *gin.Engine) {
	//跨域
	r.Use(middleware.Cors())

	api := r.Group("/api")
	{
		//客服
		admin := api.Group("/admin")
		{
			//注册、登录
			admin.POST("/register", handler.Register)
			//分页展示
			admin.GET("/list", handler.GetUserList)
			//列表
			admin.GET("/getUser", handler.GetUser)
			//图片上传
			admin.POST("/uploadFile", handler.UploadImage)
			//发布公告
			admin.POST("/sendMessage", handler.SendGroupMessage)
		}
		//token认证
		api.Use(gojwt.JWTAuth(consts.JWT_KEY))

		//chat
		chat := api.Group("/chat")
		{
			//token认证
			chat.Use(gojwt.JWTAuth(consts.JWT_KEY))
			//chat
			chat.GET("/ws", handler.Chat)
			//聊天记录查询
			chat.GET("/getHistory", handler.GetChatHistory)
		}
	}
}
